<template>
	<Echart
		id="leftCenter1"
		:options="options"
		class="left_center_inner"
		ref="echarts"
	/>
</template>

<script>
import { scoInfo } from "@/api/modules/energyunit.js";
import { graphic } from "echarts";

export default {
	props: ["info"],
	computed: {
		isCollapse() {
			return this.$store.state.isCollapse;
		},
	},
	watch: {
		info: {
			handler(newValue, oldValue) {
				if (newValue) {
					this.init();
				}
			},
			deep: true,
		},
		isCollapse(oldVal, newVal) {
			if (oldVal !== newVal) {
				this.$refs.echarts.resize();
			}
		},
	},
	data() {
		return {
			options: {},
		};
	},
	methods: {
		init() {
			this.options = {
				legend: {
					x: "center", //可设定图例在左、右、居中
					y: "10px",
					data: [this.info.cname],
					textStyle: {
						fontSize: 12,
						color: "#F1F1F3",
					},
				},
				xAxis: {
					type: "category",
					data: this.info.xData,
					boundaryGap: false, // 不留白，从原点开始
					splitLine: {
						show: true,
						lineStyle: {
							color: "rgba(31,99,163,.2)",
						},
					},
					axisLine: {
						// show:false,
						lineStyle: {
							color: "rgba(31,99,163,.1)",
						},
					},
					axisLabel: {
						color: "#7EB7FD",
						fontWeight: "500",
					},
				},
				yAxis: {
					name: `单位 :${this.info.unit}`,
					type: "value",
					nameTextStyle: {
						color: "#fff",
						fontSize: 12,
					},
					splitLine: {
						show: true,
						lineStyle: {
							color: "rgba(31,99,163,.2)",
						},
					},
					axisLine: {
						lineStyle: {
							color: "rgba(31,99,163,.1)",
						},
					},
					axisLabel: {
						color: "#7EB7FD",
						fontWeight: "500",
					},
				},
				tooltip: {
					trigger: "axis",
					backgroundColor: "rgba(0,0,0,.6)",
					borderColor: "rgba(147, 235, 248, .8)",
					textStyle: {
						color: "#FFF",
					},
				},
				grid: {
					//布局
					show: true,
					left: "30px",
					right: "30px",
					bottom: "10px",
					top: "48px",
					containLabel: true,
					borderColor: "#1F63A3",
				},
				series: [
					// {
					//   data: yData,
					//   type: "line",
					//   symbol: "circle",
					//            //           //   itemStyle: {
					//     color: "#fd754b",
					//   },
					//   name: "有功功率",
					//   areaStyle: {
					//     //右，下，左，上
					//     color: new graphic.LinearGradient(
					//       0,
					//       0,
					//       0,
					//       1,
					//       [
					//         {
					//           offset: 0,
					//           color: "rgba(252,144,16,.7)",
					//         },
					//         {
					//           offset: 1,
					//           color: "rgba(252,144,16,.0)",
					//         },
					//       ],
					//       false
					//     ),
					//   }
					// },
					{
						data: this.info.yData,
						type: "line",
						symbol: "none",
						//点样式
						itemStyle: {
							color: "#5083FF",
						},
						name: this.info.cname,
						areaStyle: {
							//右，下，左，上
							borderRadius: [2, 2, 0, 0], //柱体圆角
							color: new graphic.LinearGradient(
								0,
								0,
								0,
								1,
								[
									{
										offset: 0,
										color: "rgba(24,210,181,.35)",
									},
									{
										offset: 1,
										color: "rgba(30,231,231,1)",
									},
								],
								false
							),
						},
					},
				],
			};
		},
	},
};
</script>
<style lang="scss" scoped></style>
